package com.gaozhaoyang.servlet;

import com.gaozhaoyang.entity.User;
import com.gaozhaoyang.service.UserService;

import javax.jws.WebService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    UserService service = new UserService();
    /*
    * req.getParameter(key) 根据请求的key获取value
    * */
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.接受请求中携带的参数
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        //2.调用业务
        User user = service.login(username, password);
        //3.根据处理结果作出响应
        if (user == null){
            System.out.println("登陆失败");
        }else {
            System.out.println("登陆成功");
        }
    }
}
